package cn.itzzx.lagou.demo.controller;

import cn.itzzx.lagou.framework.annotation.LagouController;
import cn.itzzx.lagou.framework.annotation.LagouRequestMapping;
import cn.itzzx.lagou.framework.annotation.Security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 基于 Method 控制权限
 * @author Martin
 * @since 1.0
 */
@LagouController
@LagouRequestMapping("/demo")
public class DemoController {


    /**
     * 拥有权限的方法
     *  http://localhost:8080/demo/index?username=zhangsan
     * @param request
     * @param response
     * @param username
     * @return
     */
    @LagouRequestMapping("/index")
    @Security(value = {"zhangsan"})
    public void index(HttpServletRequest request, HttpServletResponse response,String username) throws IOException {
        System.out.println("执行 DemoController#index 方法");
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("DemoController#index welcome");
    }


    /**
     * 没有权限的方法
     *  http://localhost:8080/demo/notAuth?username=zhangsan
     * @param request
     * @param response
     * @param username
     * @return
     */
    @LagouRequestMapping("/notAuth")
    public String notAuth(HttpServletRequest request, HttpServletResponse response,String username){
        return "index";
    }

}
